package ch.zbw.pra.sysventory.dataaccess.dataAccessObject;

import java.io.Serializable;
import java.util.List;

import org.springframework.context.ApplicationContext;

import ch.zbw.pra.sysventory.database.jdbcTemplate.ProcessorJDBCTemplate;
import ch.zbw.pra.sysventory.model.Processor;
import ch.zbw.pra.sysventory.utils.DatabaseUtils;

/**
 * Bereitet Daten für den Zugriff auf die Datenbank im DatabaseLayer auf
 * 
 * @author Ralph Koster & Roberto Lucas
 */

public class ProcessorDataAccessObject implements Serializable {

	private static final long serialVersionUID = -1656243064187246903L;
	private ApplicationContext context;
	private ProcessorJDBCTemplate processorJDBCTemplate;
	
	public ProcessorDataAccessObject() {
		context = DatabaseUtils.getContext();
		processorJDBCTemplate = (ProcessorJDBCTemplate)context.getBean("processor");
	}

	public List<Processor> getAllProcessorFromDatabase() {
		List<Processor> processors = processorJDBCTemplate.listProcessors();
		return processors;
	}

	public Processor getProcessorFromComputer(Integer computerId) {
		Processor processor = processorJDBCTemplate.readProcessorFromComputer(computerId);
		if(null == processor) {
			processor = new Processor();
		}
		return processor;
	}

	public Integer writeProcessorToDatabase(Processor processor, Integer computerId) {
		Integer processorId = processorJDBCTemplate.insertProcessor(processor, computerId);
		return processorId;
		
	}

}
